package com.cloudbroker.bcs.platform.dav.middle.service.impl;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.common.model.Pagination;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.plugs.result.ExtendAppBuyedListData;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.plugs.result.ExtendAppWithPlugsResult;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.plugs.vo.ExtendAppBuyedListDbForm;
import com.cloudbroker.bcs.platform.dav.middle.dao.ExtendAppDAO;
import com.cloudbroker.bcs.platform.dav.middle.entity.ExtendApp;
import com.cloudbroker.bcs.platform.dav.middle.entity.ExtendAppGroup;
import com.cloudbroker.bcs.platform.dav.middle.service.ExtendAppService;
import com.cloudbroker.bcs.platform.dav.middle.service.base.TenantServiceImplBase;

@Service
public class ExtendAppServiceImpl extends TenantServiceImplBase<ExtendApp, String> implements ExtendAppService{

	@Resource
	private ExtendAppDAO extendAppDAO;
	
	@Override
	protected ExtendAppDAO getDAO(){
		return extendAppDAO;
	}

	@Override
	public List<ExtendAppBuyedListData> listWithPlugs(
			ExtendAppBuyedListDbForm form,Pagination page) {
        int count = listCountWithPlugs(form);
        if (null == page) {
            page = form.getPage();
        }
        page.setTotal_item_num(count);
        int startIndex = (page.getPage_no() <= 0 ? 0 : page.getPage_no() - 1) * page.getPage_size();
        page.setStart_index(startIndex);
        form.setPage(page);
        
		return extendAppDAO.listWithPlugs(form);
	}

	@Override
	public Integer listCountWithPlugs(ExtendAppBuyedListDbForm form) {
		return extendAppDAO.listCountWithPlugs(form);
	}

	@Override
	public void deleteByCondition(String key, Integer tenant_id) {
		extendAppDAO.deleteByCondition(key, tenant_id);
	}

	@Override
	public Long getMaxSort(ExtendApp form) {
		Long maxNum = extendAppDAO.getMaxSort(form);
		return maxNum == null ? 0 : maxNum+1L;
	}

    @Override
    public void deleteAll() {
        extendAppDAO.deleteAll();
    }

    @Override
    public ExtendAppWithPlugsResult getAppPropById(ExtendAppGroup extendAppGroup) {
        extendAppGroup.setTenant_id(getTenantId());
        return extendAppDAO.getAppPropById(extendAppGroup);
    }

}
